package com.original.simuladores.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.original.simuladores.entities.TaxIndex;
import com.original.simuladores.service.TaxIndexService;

@RestController
public class TaxIndexController {
	@Autowired
	TaxIndexService taxIndexService;
	
	@RequestMapping(value = "/taxindexs", method = RequestMethod.GET, headers = "Accept=application/json")
	public List<TaxIndex> getAllTaxIndexs() {
		return taxIndexService.getTaxIndexs();
	}
	
	@RequestMapping(value = "/taxindexs/{taxIndexId}", method = RequestMethod.GET, headers = "Accept=application/json")
	public TaxIndex getTaxIndexById(@PathVariable String taxIndexId) {
		TaxIndex taxIndex = new TaxIndex();
		List<TaxIndex> taxindexs = taxIndexService.getTaxIndexById(taxIndexId);
		if (taxindexs != null && taxindexs.size() > 0) {
			taxIndex = taxindexs.get(0);
		}
		return taxIndex;
	}
	
	@RequestMapping(value = "/taxindexs/delete/{taxIndexId}", method = RequestMethod.GET, headers = "Accept=application/json")
	public List<TaxIndex> deleteTaxIndex(@PathVariable String taxIndexId) {
		TaxIndex ti = new TaxIndex();
		ti.setId(taxIndexId);
		taxIndexService.delete(ti);
		return taxIndexService.getTaxIndexs();
	}
	
	@RequestMapping(value = "/taxindexs/insert/{taxIndexName}/{taxIndexDescription}/{taxIndexVlTaxAmount}"
			, method = RequestMethod.GET, headers = "Accept=application/json")
	public List<TaxIndex> insertTaxIndex(@PathVariable String taxIndexName
			, @PathVariable String taxIndexDescription
			, @PathVariable Float taxIndexVlTaxAmount) {
		TaxIndex ti = new TaxIndex();
		ti.setId(taxIndexService.getId());
		ti.setNm_tax(taxIndexName);
		ti.setDs_tax(taxIndexDescription);
		ti.setVl_tax_amount(taxIndexVlTaxAmount);
		taxIndexService.create(ti);
		return taxIndexService.getTaxIndexs();
	}
	
	@RequestMapping(value = "/taxindexs/update/{taxIndexId}/{taxIndexName}/{taxIndexDescription}/{taxIndexVlTaxAmount}"
			, method = RequestMethod.GET, headers = "Accept=application/json")
	public List<TaxIndex> updateTaxIndex(@PathVariable String taxIndexId
			, @PathVariable String taxIndexName
			, @PathVariable String taxIndexDescription
			, @PathVariable Float taxIndexVlTaxAmount) {
		
		TaxIndex ti = new TaxIndex();
		
		ti.setId(taxIndexId);
		ti.setNm_tax(taxIndexName);
		ti.setDs_tax(taxIndexDescription);
		ti.setVl_tax_amount(taxIndexVlTaxAmount);;
		taxIndexService.update(ti);
		return taxIndexService.getTaxIndexs();
	}
	
}
